<template>
  <el-dialog title="商品调拨单详情" :close-on-click-modal="false" :visible.sync="visible" center fullscreen>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form :model="dataForm" ref="dataForm" label-width="80px">
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="申请部门" prop="outDeptId">
            <el-select v-model="dataForm.outDeptId" disabled>
              <el-option v-for="item in deptOptions" :key="item.value" :label="item.name" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="接收部门" prop="inDeptId">
            <el-select v-model="dataForm.inDeptId" disabled>
              <el-option v-for="item in deptOptions" :key="item.value" :label="item.name" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8"></el-col>
      </el-row>
      <el-row :gutter="15">
        <el-col :span="24">
          <el-form-item label="备注" prop="stockId">
            <el-input type="textarea" :rows="2" v-model="dataForm.memo" disabled></el-input>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading">
      <el-table-column prop="barcode" header-align="center" align="center" label="商品代码"></el-table-column>
      <el-table-column prop="name" header-align="center" align="center" label="商品名称"></el-table-column>
      <el-table-column prop="spec" header-align="center" align="center" label="型号"> </el-table-column>
      <el-table-column prop="applyQuantity" header-align="center" align="center" label="数量"></el-table-column>
    </el-table>
  </el-dialog>
</template>

<script>
    import {allocationApplyGetObj} from '@/api/eims/allocation-apply'
    import {getDeptInfo} from '@/api/admin/dept'
    export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          applyStatus: '2',
          outDeptId: '',
          outDeptName: '',
          inDeptId: '',
          inDeptName: '',
          memo: '',
          detailList: []
        },
        deptOptions: [],
        dataList: [],
        dataListLoading: false,
      }
    },
    methods: {
      init (id) {
        this.getDeptList()
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            allocationApplyGetObj(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data.data
                let goodsData = response.data.data.data.detailList
                this.dataList = goodsData
                for(let i = 0; i < this.dataList.length; i++){
                  this.dataForm = response.data.data.data
                  this.dataList = response.data.data.data.detailList
                  this.dataList.forEach(item => {
                    item.barcode = item.goods.barcode
                    item.name = item.goods.name
                    item.spec = item.goods.spec
                  })
                }
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        })
      },
      /*
      * *  获取所需数据字典
      */
     getDeptList(){
       getDeptInfo().then(result => {
         let dataList = result.data.data
         let options = []
         dataList.forEach(item => {
           options.push({value:item.id,name:item.name})
         })
         this.deptOptions = options
       })
     }
    }
  }
</script>
